<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Makumba-Hibernate QL differences</title>
<link rel="stylesheet" type="text/css" media="all" href="../main.css">
<script type="text/javascript" src="../main.js"></script>
</head>
<body>
<script type="text/javascript">
   makeNavBar("../");
</script>
Here are the presently known issues with the makumba - HQL query transition.
<br>
Note that all the indicated Makumba queries do pass the HQL parser. They will not however pass the HQL-SQL translator
(in the ptr and set join cases) or have a different semantic (in the other cases).
<br>
The rightmost column suggests ways to automatically translate the Makumba OQL (once passed by the HQL parser) into HQL
that would pass the HQL-SQL translator.
<br>
It is interesting to note that a label means different things in the Hibernate FROM and SELECT sections. In FROM, it is
a pointer/reference, in SELECT it is a whole object. Makumba is more consistent in this area (hence the suggestions
below).
<br>
<br>
<table style="text-align: left; width: 100%;" border="1" cellspacing="2" cellpadding="2">
  <tbody>
    <tr>
      <td style="vertical-align: top; text-align: center;">Makumba OQL<br>
      </td>
      <td style="vertical-align: top; text-align: center;">Hibernate HQL<br>
      </td>
      <td style="vertical-align: top;">problem<br>
      </td>
      <td style="vertical-align: top;">comment<br>
      </td>
      <td style="vertical-align: top;">suggested resolution<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT i.surname, p.weight FROM test.Person p, <span
        style="font-weight: bold;">p.indiv i</span> WHERE i.name = 'Bart'</td>
      <td style="vertical-align: top;">SELECT i.surname, p.weight FROM test.Person p<span
        style="font-weight: bold;"> JOIN p.indiv i</span> WHERE i.name = 'Bart'</td>
      <td style="vertical-align: top;" rowspan="3">ptr and set joining</td>
      <td style="vertical-align: top;" rowspan="3">Hibernate set and pointer joining is not as obvious as in
      Makumba but most probably more flexible (IN operator more powerful)<br>
      Generated Hibernate SQL uses JOIN... ON (while&nbsp; makumba's will use supplementary WHERE conditions, one for
      pointers, one for sets). <br>
      <br>
      Note that this is the case for all kinds of Makumba sets.<br>
      <br>
      Instead of JOIN p.indiv i, one can use the equivalent form , IN (p.indiv) i<br>
      <br>
      This problem is more important for sets, for pointers you can always use<span style="font-weight: bold;">
      p.indiv</span> instead of<span style="font-weight: bold;"> i </span>in the SELECT and WHERE expressions.</td>
      <td style="vertical-align: top;" rowspan="3">Accept at JSP level but recommend/train people with the
      Hibernate form</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT s.name FROM test.Person p<span style="font-weight: bold;">,
      p.speaks s</span> WHERE p.indiv.name = 'Bart'</td>
      <td style="vertical-align: top;">SELECT s.name FROM test.Person p <span style="font-weight: bold;">JOIN
      p.speaks s</span> WHERE p.indiv.name = 'Bart'</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT a.streetno FROM test.Person p<span style="font-weight: bold;">,
      p.address a</span></td>
      <td style="vertical-align: top;">SELECT a.streetno FROM test.Person p, <span style="font-weight: bold;">JOIN
      p.address a</span></td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT <span style="font-weight: bold;">p.indiv</span> FROM test.Person p<br>
      </td>
      <td style="vertical-align: top;">SELECT <span style="font-weight: bold;">p.hibernate_indiv</span> FROM
      test.Person p<br>
      </td>
      <td style="vertical-align: top;">ptr projection<br>
      </td>
      <td style="vertical-align: top;">In Hibernate, p.indiv would select the whole test.Individual because
      Hibernate is oriented towards selecting whole objects, not just fields. The current solution is to map (in the
      test.Person mapping file) pointers like indiv twice: once as a relation to test.Individual (which allows selection
      of the whole object) and second as a value with the name hibernate_indiv (which allows selection of the pointer
      value without joining the test.Individual table). Maybe a better name can be chosen (e.g. indivPtr instead of
      hibernate_indiv).<br>
      </td>
      <td style="vertical-align: top;">Selecting whole objects<br>
      (&lt;mak:value expr="p.indiv" /&gt;) makes little sense at JSP level. <br>
      Accept the current makumba form and translate into the Hibernate form. NOT sure if the Makumba form should be
      deprecated (like in other cases)<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">SELECT <span style="font-weight: bold;">p</span> FROM
      test.Person p<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">SELECT <span style="font-weight: bold;">p.id</span>
      FROM test.Person p<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">primary key projection<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">In Hibernate, p would select the whole test.Person
      because Hibernate is oriented towards selecting whole objects, not just fields. The current solution is to use the
      Hibernate-level field name (id) of the Makumba primary key<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">Selecting whole objects <br>
      (&lt;mak:value expr="p" /&gt;) makes little sense at JSP level. <br>
      Accept the current makumba form and translate into the Hibernate form BUT but recommend/train people with the
      Hibernate form.</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT <span style="font-weight: bold;">s </span>FROM test.Person p, <span
        style="font-weight: bold;">p.intSet s</span><br>
      </td>
      <td style="vertical-align: top;">SELECT<span style="font-weight: bold;"> s.enum_ </span>FROM test.Person p <span
        style="font-weight: bold;">JOIN p.intSet s</span></td>
      <td style="vertical-align: top;">int/charEnum projection<br>
      </td>
      <td style="vertical-align: top;">A combination of set joining and label projection. Selecting s would select
      the whole enumerator object, which is typically useless. Selecting enum (the hidden mdd's field name) leads to a java reserved keyword problem<br>
      </td>
      <td style="vertical-align: top;">Accept the current makumba form and translate into the Hibernate form. NOT
      sure if the Makumba form should be deprecated (like in other cases)</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">label.field=nil<br>
      label.field &lt;&gt; nil<br>
      </td>
      <td style="vertical-align: top;">label.field is null<br>
      label.field is not null<br>
      </td>
      <td style="vertical-align: top;">null comparisson<br>
      </td>
      <td style="vertical-align: top;">Hibernate follows SQL. <br>
      </td>
      <td style="vertical-align: top;">While the above Makumba notations are syntactically correct in HQL, this one
      is probably not. Maybe it's easier to change the existing JSPs.<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT x &gt; y FROM...<br>
      </td>
      <td style="vertical-align: top;">BUG, HQL error<br>
      </td>
      <td style="vertical-align: top;">selecting logical expression<br>
      </td>
      <td style="vertical-align: top;">HQL cannot directly select logical expressions, so using
      mak:if is a problem<br><br>
      HQL understands things of the kind "case when (logical expression) then 1 else 0 end".<br><br>
      </td>
      <td style="vertical-align: top;">FIXED. mak:if now adopts this syntax when translating the query
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT a.b.c FROM A a... <br>
      </td>
      <td style="vertical-align: top;">BUG, generated SQL misses a comma in the FROM section<br>
      </td>
      <td style="vertical-align: top;"><br>
      </td>
      <td style="vertical-align: top;">HQL has problems with multiple dereferencing<br>
      </td>
      <td style="vertical-align: top;">FIXED in the last Hibernate version<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT x as y FROM z ORDER BY y<br>
      </td>
      <td style="vertical-align: top;">BUG, HQL error<br>
      </td>
      <td style="vertical-align: top;">group by statement using labels<br>
      </td>
      <td style="vertical-align: top;">HQL does not support the possiblity of using labels in the ORDER BY clause.<br>
      </td>
      <td style="vertical-align: top;">FIXED by a workaround that replaces the label by its expression, ie. SELECT x as y FROM z ORDER BY x.<br>
      <br>
      We should watch if the next Hibernate releases will deal with this.
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT a FROM b WHERE b.name=$someParam</td>
      <td style="vertical-align: top;">SELECT a FROM b WHERE b.name=:someParam</td>
      <td style="vertical-align: top;">Different way of marking an attribute, "$" vs ":"</td>
      <td style="vertical-align: top;">Still to be decided whether we want to keep it like this, or enforce $ and
      translate it.<br>
      However, the general policy was to use HQL directly and not to translate into it.</td>
      <td style="vertical-align: top;">Do nothing.</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">SELECT <span style="font-weight: bold;">p.id</span> FROM test.Person p<br>
      </td>
      <td style="vertical-align: top;">SELECT <span style="font-weight: bold;">p.id</span> FROM test.Person p<br>
      </td>
      <td style="vertical-align: top;">Selecting fied with special name<br>
      </td>
      <td style="vertical-align: top;">In Hibernate .id is a reserved element, used when declaring the primary key in mappings.<br><br>
      In some MDDs, there are however fields called "id" which confuse Hibernate when selected normally.<br>
      </td>
      <td style="vertical-align: top;">Don't allow "id" in MDDs</td>
    </tr>
    <tr>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">SELECT p.name FROM test.Person p WHERE <span style="font-weight: bold;">p.hobby = 'sailing'</span><br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">SELECT p.name FROM test.Person p WHERE <span style="font-weight: bold;">p.hobby = 10</span><br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">parameter type<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">In OQL, 'sailing' is translated into its database value. In Hibernate, this is not the case yet, intEnum being specific to Makumba<br>
      </td>
      <td style="vertical-align: top; color: rgb(153, 0, 0);">Extend the HQL analyzer and perform the translation when needed.<br><br>
      Maybe a direct translation in Hibernate could be done while generating the mappings, e.g.<br><br>
      public enum EventStatus {<br>
        FINISHED("Finished, whatever else there was", 10),<br>
        CANCELLED("Cancelled", 20),<br>
        SOME_OTHER_STATE(....);<br>
        <br>
        private String endUserPresentation;<br>
        private int dbLevelValue;<br>
        EventStatus(String s, int n)<br>
            { endUserPresentation=s; dbLevelValue=n; }<br>
        }<br>
        <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
</body>
</html>
